package com.tree.mybatisplus.user.controller;


import com.tree.common.annotation.ResponseResult;
import com.tree.common.controller.BaseController;
import com.tree.common.exception.AppException;
import com.tree.mybatisplus.user.entity.User;
import com.tree.mybatisplus.user.service.IUserService;
import com.tree.mybatisplus.user.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tree
 * @since 2019-05-28
 */
@ResponseResult
@RestController
@RequestMapping("/user")
public class UserController  extends BaseController<UserServiceImpl,User> {

    @Autowired
    private IUserService userService;

    @GetMapping("/getUser")
    public List<User> getUser(){
//        userService.page()
        return userService.list();
    }

    @GetMapping("/ex")
    public User ex()  {
//        userService.page()
        throw new AppException("test exception");
//        return userService.getById(1);
    }

    @PostMapping("/save")
    public boolean save(@RequestBody @Valid User user){
        return userService.save(user);
    }

}
